<div id="leftContent">

<h1>Project</h1>
<p>One project has a source code and details of implementation, which will be reported for each cluster. For a project, there are one or more <i>jobs</i> for the various tasks and various files for processing.</p>

<h1>Job</h1>
<p>For each zipped file inside the <i>project input file</i> one job will be created. Job is an atomic part off all the work being done in a project. A job runs on a cluster, which is connected to the Interop Router.</p>

<h1>Result</h1>
<p>For each captured job, two results are issued depending on the job's output: the standard output and the error output. These results are only released after the end of the job's execution.</p>

</div>

<div id="mainContent">

<?php

if ($flagDB == false)
{ // database off
	echo "<h1>Projects</h1>";
	echo "<p>At moment, our database is offline.</p>";
}
else
{ // database on
	if ($flagResult == false)
	{ // couldn't find any entry
		if ($flagType == "projects")
		{ // data type = projects
			echo "<h1>Projects</h1>";
			echo "<p>You didn't submit any project.</p>";
		}
		else
		{ // data type= jobs
			echo "<h1>Jobs</h1>";
			echo "<p>Our database returned an invalid result.<br>This means that database has a problem.<br>Please, contact the administrator.</p>";
		}
	}
	else
	{ // there are at least one entry
		if ($flagType == "projects")
		{ // data type = projects
			?>
				<h1>Projects</h1>
				<table id="projectsTable" cellspacing="0">
				<tr class="header"><th class="spacer"></th><th class="name">Name</th><th class="date">Date</th><th class="source">Source Code</th></tr>
			<?php
			for ($i=0; ($i < count($data)); $i++)
			{
			?>
				<tr class="item">
				<td><img src="images/spacer.gif" width="17px" height="35" /></td>
				<td class="name"><a href="projetos.php?projectId=<?=$data[$i]["projectId"];?>"><?=$data[$i]["projectName"];?></a></td>
				<td><?=substr($data[$i]["projectDate"],0,10);?></td>
				<td><a href="download.php?from=projects&field=projectSourceFile&index=<?=$data[$i]["projectId"];?>"><img src="images/download.gif" /> download</a></td>
				</tr>
			<?php
			}
			?>
				</table>
			<?php
		}
		else
		{ // data type= jobs
			?>
				<h1>Jobs</h1>
				<h2>Project: <?=$projectName;?></h2>
				<table id="jobsTable" cellpadding="0" cellspacing="0">
				<tr class="header"><th class="name">Name</th><th class="input">Datafile</th><th class="status">Status</th><th class="output">Output log</th><th class="error">Error log</th></tr>
			<?php
			for ($i=0; ($i < count($data)); $i++)
			{
			?>
				<tr class="item">
				<td class="name"><?=$data[$i]["jobName"];?></td>
				<td><a href="download.php?from=jobs&field=jobDataFile&index=<?=$data[$i]["jobId"];?>"><img src="images/download.gif" /> download</a></td>
			<?php
				switch ($data[$i]["jobStatus"])
				{
					case 0: // job on waiting, logs aren`t prepared
						?>
						<td><div class="waiting">waiting</div></td>
						<td><img src="images/clock.gif" /> download</td>
						<td><img src="images/clock.gif" /> download</td>
						<?php
						break;
					
					case 1: // job on processing, logs aren`t prepared
						?>
						<td><div class="running">processing</div></td>
						<td><img src="images/clock.gif" /> download</td>
						<td><img src="images/clock.gif" /> download</td>
						<?php
						break;
					
					case 2: // job finished, have logs
						?>
						<td><div class="finished">finished</div></td>
						<td><a href="download.php?from=results&field=resultOutput&index=<?=$data[$i]["jobId"];?>"><img src="images/download.gif" /> download</a></td>
						<td><a href="download.php?from=results&field=resultError&index=<?=$data[$i]["jobId"];?>"><img src="images/download.gif" /> download</a></td>
						<?php
						break;
					
					case 3: // job cancelled, have no logs, log ignored
						?>
						<td><div class="canceled">cancelled</div></td>
						<td><img src="images/cancel.gif" /> download</td>
						<td><img src="images/cancel.gif" /> download</td>
						<?php
						break;
					
					default: // job generated an error, have logs
						?>
						<td><div class="error">error</div></td>
						<td><a href="download.php?from=results&field=resultOutput&index=<?=$data[$i]["jobId"];?>"><img src="images/download.gif" /> download</a></td>
						<td><a href="download.php?from=results&field=resultError&index=<?=$data[$i]["jobId"];?>"><img src="images/download.gif" /> download</a></td>
						<?php
						break;
				}
				echo "</tr>";
			}
			?>
				</table>
			<?php
		}
	}
}

?>

</div>